window.topPage={
	/*搜索点击效果*/ 
	clickbg:function(){
		$('div').delegate('.s-menu ul li a','click',function(){
			$('.s-menu ul li a:not(this)').removeClass('active'); 
			$(this).addClass('active');
			var search_url = 'index.php?do=' + $(this).attr('rel');
			$('#topHeaderSearch').attr('action',search_url);
			$('#hidden_search').attr('value',$(this).attr('rel'));
		});
	},
	/*分类显示效果*/ 
	dislist:function(){
		// var divH=$('.sibar-l-main').height()-30;
		// $('.sibar-l-main ul li').children('.navlist').css('height',divH);
		$('.sibar-l-main ul li').hover(
			function(){
				$('.sibar-l-main ul li:not(this)').children('.navlist').css('display','none');
				$(this).children('.navlist').css('display','block');
			},
			function(){
				$(this).children('.navlist').css('display','none');
			});

	},

	/*我的钱包tab*/
	walTab:function(){
		$('div.wa-tlist>ul>li>a').each(function(i){
			$(this).click(function(){
				$(this).addClass('active').parent('li').siblings('li').children('a').removeClass('active');
				$('div.wa-tab'+i).css('display','block').siblings().css('display','none');
			})
		});

	},


/*我的店铺的tab*/ 
shpTab:function(){
	$('#shpc0').css('display','block');
	// $('#shplist>ul>li>a').eq(0).addClass('active');
	$('#shplist>ul>li>a').each(function(i){
		$(this).click(function(){
			$(this).addClass("active").parent('li').siblings('li').children('a').removeClass('active');
			$('#shpc'+i).css('display','block').siblings().css('display','none');
		});
	});
	$(document).delegate('#addser','click',function(){
		$('#shpadd0').css('display','block').siblings('div').css('display','none');
	});
		$(document).delegate('#addCase','click',function(){
		$('#shpadd1').css('display','block').siblings('div').css('display','none');
	});
},
/*删除操作*/ 
delItem:function(){
	// $(document).delegate('.icon-del','click',function(){
	// 	$(this).parent().parent().remove();
	// });
},
editor_limit:function(){
	$(document).delegate('#editorDcrit','focus keydown deyup change',function(){
		var $text=$(this);
		var totalWordsCount = 200;
		var dynamicContent = $text.val();
		var dynamicContentLength = dynamicContent.length;
		var wordsCount = 0;
		for(var i=0;i<dynamicContentLength;i++){
			var charCode = dynamicContent.charCodeAt(i);
			if((charCode >= 0x0001 && charCode <= 0x007e) || (0xff60<=charCode &&charCode<=0xff9f)){
				wordsCount+=0.5;
			}else{
				wordsCount++;
			}
			var leftWordsCount = totalWordsCount - Math.ceil(wordsCount);
			if(leftWordsCount >=0){
				$(this).siblings('.promt').html('还可以输入'+leftWordsCount+'字');
			}else{
				leftWordsCount = Math.ceil(wordsCount) - totalWordsCount;
				$(this).siblings('.promt').html('超出'+leftWordsCount+'字').addClass('fontRed');
			}
		}
	});
},
editorLimit:function(){
	$(document).delegate('#editComplain','focus keydown deyup change',function(){
		var $text=$(this);
		var totalWordsCount = 140;
		var dynamicContent = $text.val();
		var dynamicContentLength = dynamicContent.length;
		var wordsCount = 0;
		for(var i=0;i<dynamicContentLength;i++){
			var charCode = dynamicContent.charCodeAt(i);
			if((charCode >= 0x0001 && charCode <= 0x007e) || (0xff60<=charCode &&charCode<=0xff9f)){
				wordsCount+=0.5;
			}else{
				wordsCount++;
			}
			var leftWordsCount = totalWordsCount - Math.ceil(wordsCount);
			if(leftWordsCount >=0){
				$(this).siblings('.txtpit').html('还可以输入'+leftWordsCount+'字');
			}else{
				leftWordsCount = Math.ceil(wordsCount) - totalWordsCount;
				$(this).siblings('.txtpit').html('超出'+leftWordsCount+'字').addClass('fontRed');
			}
		}
	});
},
/*分页*/ 
// changePage:function(currentPage){
// 	totalPage=13;/*总页数*/
// 	pageIndex=1/*当前选中的页码*/
// 	everyPageCount=5/*每页显示页码数*/
// 	pageStart=1;/*每页的起始页码*/
// 	pageEnd=1;/*每页的终止页码*/
// 	var outHtml='<span>'+currentPage+'/'+totalPage+'页</span>';
// 	if(currentPage>3){
// 			pageEnd=currentPage+2;
// 			/*判断最后一页是否大于总页数*/
// 			if(pageEnd>totalPage)
// 			{
// 				pageEnd=totalPage;
// 			}
// 			pageStart=pageEnd-(everyPageCount-1);		
// 		}
// 		else{
// 			pageStart=1;
// 			pageEnd=everyPageCount>totalPage?totalPage:everyPageCount;
// 		}
// 		if(currentPage!=1){
// 			outHtml=outHtml+'<a herf="javascript:void(0)" onclick="changePage('+(currentPage-1)+')">上一页</a>'
// 		}
// 		for(;pageStart<=pageEnd;pageStart++){
// 			if(pageStart!==currentPage){
// 				outHtml=outHtml+'<a herf="javascript:void(0)" onclick="changePage('+pageStart+')">'+pageStart+'</a>';
// 			}else{
// 				outHtml=outHtml+'<span class="current">'+pageStart+'</span>';
// 			}
// 		}
// 		if(currentPage !=totalPage){
// 			outHtml=outHtml+'<a herf="javascript:void(0)" onclick="changePage('+(currentPage+1)+')">下一页</a>'
// 		}
// 		outHtml=outHtml+'<input type="text"  name="changePage" onkeyup="jumpCheck(this)" class="textinput" id="txtNum" value=""><label id="go" for="changePage">跳转</label>'
// 	  $('#page').html(outHtml);

// },
/*我的消息的tab*/
newsTab:function(){
	// $('.news-list>ul>li>a').eq(0).addClass('active');
	$('.newsm').eq(0).css('display','block');
	$('.news-list>ul>li>a').each(function(index){
		$(this).click(function(){
			$(this).addClass('active').parent('li').siblings('li').children('a').removeClass('active');
			$('.newsm').eq(index).css('display','block').siblings('.newsm').css('display','none');
		});
	});
},
 /*消息全选与取消全选*/ 
 checkAll:function(){
 	$(document).delegate('.label-m input[name=checkbox]','click',function(){
 		if($(this).is(':checked')){
 			 $(this).parent().parent().siblings('.news-t').children('table').children('tbody').children('tr').children('td').children('input').prop('checked',true);
 		}else if(!$(this).is(':checked')){
	 		 $(this).parent().parent().siblings('.news-t').children('table').children('tbody').children('tr').children('td').children('input').attr('checked',false);
	 		
 		}
 	});
 	
 },
 /*右边浮动窗悬停事件*/
 disLink:function(){
 	// $('.toolbtn').on('mouseenter',function(){
 	// 	$(this).children('.link_main').show();
 	// });
 	// $('.toolbtn').on('mouseleave',function(){
 	// 	$(this).children('.link_main').hide();
 	// });
	$('.toolbtn').hover(function() {
		$(this).children('.link_main').show();
	}, function() {
		$(this).children('.link_main').hide();
	});
 	
 
 } 
}
/*执行*/ 
jQuery(document).ready(function($) {
	topPage.clickbg();
	topPage.dislist();
	topPage.walTab();
	topPage.shpTab();
	topPage.delItem();
	topPage.editor_limit();
	topPage.newsTab();
	topPage.checkAll();
	topPage.editorLimit();
	topPage.disLink();
	//返回顶部
	 $(window).scroll(function(){
	  if ($(window).scrollTop()>500){
	    $("#goUp").fadeIn();
	  }
	  else
	  {
	    $("#goUp").fadeOut();
	  }
	  });
	//当点击跳转链接后，回到页面顶部位置
	  $("a#top").click(function(){
	    $('body,html').animate({scrollTop:0},500);
	     return false;
	});
	// topPage.changePage(1);
	/*日期时间选择器*/
	$("#datetimepickerStart,#datetimepickerEnd").datetimepicker({
		format: 'yyyy-mm-dd',
		language:'zh-CN',
		// autoclose:1,
		minView: "month",
		todayBtn: 1
	});
});